<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function getRandom(min, max) {
        min = Math.ceil(min)
        max = Math.floor(max)
        return Math.floor(Math.random() * (max - min + 1)) + min
      }
      var x = getRandom(1, 50)
      alert('猜数字游戏:猜一个1到50之间的整数,一共有5次机会!')
      for (i = 1; i <= 5; i++) {
        var s = Number(prompt('请输入一个数字:'))
        if (s > x) {
          alert('猜大了,再来')
        } else if (s < x) {
          alert('猜小了,再来')
        } else if (s == x) {
          alert(`太强了,就是${s},奖励你一个么么哒!`)
          break
        }
        if (i == 5) {
          alert('机会用完了,刷新网页可以重来!')
        }
      }
    </script>
  </body>
</html>
